Open
Conversation
nodchip
reviewed
Mar 10, 2026
| frontier.append(root) | ||
| depth = 0 | ||
| while frontier: | ||
| num_cur_frontiers = len(frontier) |
There was a problem hiding this comment.
こちらのコメントをご参照ください。
hemispherium/LeetCode_Arai60#10 (comment)
また、 frontiers を単数にするか複数にするかについては、こちらのコメントをご参照ください。
achotto/arai60#6 (comment)
また、 current という単語については、こちらのコメントをご参照ください。
Mike0121/LeetCode#7 (comment)
自分なら num_nodes_in_level と名付けると思います。
mamo3gr
reviewed
Mar 18, 2026
Comment on lines
+179
to
+190
| frontier = deque() | ||
| frontier.append(root) | ||
| depth = 0 | ||
| while frontier: | ||
| num_cur_frontiers = len(frontier) | ||
| depth += 1 | ||
| for _ in range(num_cur_frontiers): | ||
| node = frontier.popleft() | ||
| if node is None: | ||
| continue | ||
| frontier.append(node.left) | ||
| frontier.append(node.right) |
There was a problem hiding this comment.
キューに異なる階層のノードが入っていて、かつそれらの深さはキュー外で管理されている、という構造がちょっと違和感がありました。私なら、いま見る階層と、次に見る階層を分けてスワップします。dequeが不要になるのもメリットです。
Suggested change
| frontier = deque() | |
| frontier.append(root) | |
| depth = 0 | |
| while frontier: | |
| num_cur_frontiers = len(frontier) | |
| depth += 1 | |
| for _ in range(num_cur_frontiers): | |
| node = frontier.popleft() | |
| if node is None: | |
| continue | |
| frontier.append(node.left) | |
| frontier.append(node.right) | |
| frontier = [root] | |
| depth = 0 | |
| while frontier: | |
| depth += 1 | |
| next_frontier = [] | |
| for node in frontier: | |
| if node is None: | |
| continue | |
| next_frontier.append(node.left) | |
| next_frontier.append(node.right) | |
| frontier = next_frontier |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://leetcode.com/problems/maximum-depth-of-binary-tree/description/